import request from "@/utils/request";
import type {
  GetRoleListParams,
  GetRoleListResponse,
} from "./models/roleModels";

enum Api {
  getRoleListUrl = `/admin/acl/role`,
  addRoleUrl = `/admin/acl/role/save`,
  updateRoleUrl = `/admin/acl/role/update`,
  removeRoleUrl = `/admin/acl/role/remove`,
  batchRemoveRoleListUrl = `/admin/acl/role/batchRemove`,
}

/**
 * 获取角色列表
 * @param GetRoleListParams
 * @returns GetRoleListResponse
 */
export const getRoleListApi = ({
  page,
  limit,
  roleName,
}: GetRoleListParams) => {
  return request.get<any, GetRoleListResponse>(
    Api.getRoleListUrl + `/${page}/${limit}`,
    {
      params: {
        roleName,
      },
    }
  );
};

/**
 * 添加用户
 * @param roleName 角色名称
 * @returns null
 */
export const addRoleApi = (roleName: string) => {
  return request.post<any, null>(Api.addRoleUrl, { roleName });
};

/**
 * 更新角色
 * @param id 角色id
 * @param roleName 角色名称
 * @returns null
 */
export const updateRoleApi = (id: string, roleName: string) => {
  return request.put<any, null>(Api.updateRoleUrl, { id, roleName });
};

/**
 * 删除角色
 * @param id 角色id
 * @returns null
 */
export const removeRoleApi = (id: string) => {
  return request.delete<any, null>(Api.removeRoleUrl + `/${id}`);
};

/**
 * 批量删除角色列表
 * @param idList 角色id列表
 * @returns null
 */
export const batchRemoveRoleListApi = (idList: string[]) => {
  return request.post<any, null>(Api.batchRemoveRoleListUrl, idList);
};
